<!DOCTYPE html>
<#assign ctx=Session.basePath>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加关注</title>
    <script>
        var shipid = '<#if shipid??>${shipid}<#else></#if>';
        var company =  '<#if company??>${company}<#else></#if>';
    </script>
    <link href="${ctx}/easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <link href="${ctx}/easyui/themes/icon.css" rel="stylesheet" />
    <script src="${ctx}/easyui/jquery.easyui.min.js"></script>
    <script src="${ctx}/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        function loadAll2(){
            var pager = $('#dg2').datagrid({
                fitColumns:true,
                fit: true,
                loadFilter: function(data){
                    if(data != null && data.rows != null){
                        for(var i = 0; i < data.rows.length; i++){
                            var record = data.rows[i];
                            var shipName;
                            if(record.shipName!=null){
                                shipName = record.shipName;
                            }
                            var mmsi=record.mmsi;
                            var addthis = record.addthis =  "<a href='#' onclick='addShip(\""+mmsi+"\")'>添加关注</a>";
                            record.mmsi=mmsi;
                            record.addthis = addthis;
                        }
                    }

                    return data;
                }
            });
        }
        /**
         * 添加船舶
         * @param mmsi
         */
        function addShip(mmsi){
            var id = $("#guanid").val();
            if(id == 0){
                layer.alert("请选择列表！");
                 return;
            }
            var mmsi = mmsi;
            $.messager.confirm('添加关注', '是否确认关注该船舶?', function(r){
                if (r){
                    $.ajax({
                        type: "POST",
                        url: "/manage/ship/user/addship",
                        data: {mmsi:mmsi ,id:id},
                        success:function (data) {
                            if(data.result == true){
                                layer.alert("添加成功！");
                            }else{
                                layer.alert("您已关注该船舶！");
                            }
                        }
                    })
                }
            });
        }
        $(function() {
            loadAll2();
        })
        $("#search2").click(function () {
            $('#dg2').datagrid("load",{
                shipName : $("#ship_Name").val()
            })
        })
    </script>
</head>
<body>
<div id="tb2" style="padding:5px;height:auto">
    <div>
        搜索: <input type="text" id="ship_Name" style="width:120px" placeholder="请输入船舶名称或注册号"/>
        <select id="guanid" style="width: 100px;">
            <option value="0">==请选择==</option>
<#if guanZhuList??>
        <#list guanZhuList as guanzhu>
            <option value="${guanzhu.id}">${guanzhu.name}</option>
        </#list>
</#if>
        </select>
        <a href="#" id="search2"  class="easyui-linkbutton btn-search" iconCls="icon-search" style="width: 80px;">查找</a>
    </div>
</div>
<table id="dg2"
       data-options="rownumbers:true,singleSelect:true,pagination:true,url:'${ctx}/add/ship/getAllShip?shipid=<#if shipid??>${shipid}<#else></#if>&company=<#if company??>${company}<#else></#if>',method:'post',toolbar:'#tb2'">
    <thead>
    <tr>
        <th data-options="field:'shipname',width:100">船名</th>
        <th data-options="field:'mmsi',width:60,align:'center'">MMSI</th>
        <th data-options="field:'addthis',width:60,align:'center'">添加关注</th>
    </tr>
    </thead>
</table>

</body>
</html>